import { Alova, AlovaLogin } from '@/utils/http/alova/index';

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return Alova.Get<InResult>('/admin_info', {
    meta: {
      isReturnNativeResponse: true,
    },
  });
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return Alova.Post<InResult>(
    '/login',
    {
      params,
    },
    {
      meta: {
        isReturnNativeResponse: true,
      },
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return Alova.Post(`/user/u${uid}/changepw`, { params });
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return Alova.Post('/login/logout', {
    params,
  });
}

export interface LoginResponse {
  success: boolean;
}

/**
 * @description: fpga登录方式
 */
export function fpgaLogin(data) {
  const params = new URLSearchParams();
  params.append('password', data.password);
  const url = import.meta.env.PROD ? `${window.location.origin}:3450/login` : '/login';
  return AlovaLogin.Get<LoginResponse>(`${url}?${params.toString()}`, {
    meta: {
      isReturnNativeResponse: true, // 关键配置, 返回原生响应头
    },
  });
}
